﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace YawetagLib.Data.Xml
{
    public abstract class Repository<TEntity> : CrudRepository<TEntity> where TEntity : class
    {
        protected Repository(IDataContext dataContext)
            : base(dataContext)
        {
            DataSource = (DataSource<TEntity>)GetDataSource<TEntity>();
        }

        protected IDataSource<TEntity2> GetDataSource<TEntity2>() where TEntity2 : class
        {
            return DataContext.GetDataSource<TEntity2>();
        }

        public IList<TEntity> GetWhere(Expression<Func<TEntity, bool>> predicate)
        {
            return DataSource.GetWhere(predicate);
        }

        protected new DataContext DataContext 
        {
            get { return (DataContext)base.DataContext; }
        }

        protected new DataSource<TEntity> DataSource
        {
            get { return (DataSource<TEntity>)base.DataSource; }
            set { base.DataSource = value; }
        }
    }
}
